package book.nettyinaction.ch05;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.Channel;

/**
 * 代码清单 5-15 引用计数
 *
 * @see io.netty.buffer.ByteBuf
 * @see io.netty.util.ReferenceCounted
 */
public class Demo015ReferenceCounted {
    public static void main(String[] args) {
        Channel channel = null;
        // 从 Channel 获取 ByteBufAllocator
        ByteBufAllocator allocator = channel.alloc();

        // 从 ByteBufAllocator 分配一个 ByteBuf
        ByteBuf buffer = allocator.directBuffer();

        // 检查引用计数是否为预期的 1
        assert buffer.refCnt() == 1;

    }
}
